﻿/// <summary>
/// FileName: ExpChar.cs
/// Author: Jiang Xiaolong
/// Created Time: 2015.05.12
/// Version: 1.0
/// Company: Sunnytech
/// Function: 单个公式字符存储类，方便中间过程处理，继承PositionLocate接口，便于错误定位；
///
/// Changed By:
/// Modification Time:
/// Discription:
/// </summary>
using Expression.api;

namespace Expression.impl
{
	public class ExpChar : PositionLocate
	{

		private char _value;
		private int _line;
		private int _pos;

		public ExpChar(char value, int line, int pos)
		{
			this._value = value;
			this._line = line;
			this._pos = pos;
		}

		public char GetValue()
		{
			return _value;
		}

		public int GetLine()
		{
			return _line;
		}

		public int GetPos()
		{
			return _pos;
		}

		public bool IsDigit()
		{
			return char.IsDigit(_value);
		}

		public bool IsLetter()
		{
			return char.IsLetter(_value);
		}

		public bool IsWhiteSpace()
		{
			return char.IsWhiteSpace(_value);
		}

		public bool IsNewLine()
		{
			return _value == '\n';
		}

		public bool IsEndOfInput()
		{
			return _value == '\0';
		}

		public string GetStringValue()
		{
			if (IsEndOfInput())
			{
				return "";
			}
			else
			{
				return _value.ToString();
			}
		}

		public bool Is(params char[] aim_chars)
		{
			for (int i = 0; i < aim_chars.Length; i++)
			{
				if (aim_chars[i] == _value && aim_chars[i] != '\0')
				{
					return true;
				}
			}
			return false;
		}

		public override string ToString()
		{
			if (IsEndOfInput())
			{
				return "<End Of Input>";
			}
			else
			{
				return _value.ToString();
			}
		}
	}

}